package com.sjq.common.mq.utils;

import javax.jms.Destination;
import javax.jms.ObjectMessage;
import javax.jms.Queue;

import com.sjq.common.mq.base.AbstractJMSProducer;

public class JavaDefualtProducer extends AbstractJMSProducer {
	
	private String JAVA_QUEUE_NAME;
	
	public JavaDefualtProducer(String destinationName){
		JAVA_QUEUE_NAME = destinationName;
	}

	@Override
	public String specifyDestinationName() {
		//////////////设置名字/////////////
		return JAVA_QUEUE_NAME;
	}

	@Override
	public Class<? extends Destination> specifyDestinationClass() {
		return Queue.class;
	}
	
	
	public void sendMessageToMQ(String msg) {
		try{
			System.out.println("开始发送消息"+msg+"到MQ！！！！");
			ObjectMessage message = session.createObjectMessage(msg) ;
			this.messageProducer.send(message);
		}catch(Exception ex){
			ex.printStackTrace();
			try{
				stop();
			}catch(Exception e0){
				e0.printStackTrace();
			}
			try{
				start();
			}catch(Exception e1){
				e1.printStackTrace();
			}
		}
		
		System.out.println("发送成功！！！！");
	}
	
	

}
